﻿using Md.Api.Model;
using Md.Api.Model.Manage.MdAddress.Request;
using Md.Api.Service.Manage.MdAddress;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 收货/发货地址
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/md/address")]
public class MdAddressController : ControllerBase
{
    /// <summary>
    /// 通过编号删除收货/发货地址服务
    /// </summary>
    public DeleteMdAddressByIdService deleteMdAddressByIdService { get; set; }
    /// <summary>
    /// 通过编号删除收货/发货地址
    /// </summary>
    /// <param name="addressIds">地址编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{addressIds}")]
    public async Task<ResponseMessageModel> DeleteMdAddressById(string addressIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteMdAddressByIdModel();

        model.Ids = addressIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteMdAddressByIdService.Execute(model));
    }

    /// <summary>
    /// 添加收货/发货地址服务
    /// </summary>
    public InsertMdAddressService insertMdAddressService { get; set; }
    /// <summary>
    /// 添加收货/发货地址
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertMdAddress([FromBody] RequestInsertMdAddressModel model)
    {
        return await Task.Run(() => insertMdAddressService.Execute(model));
    }

    /// <summary>
    /// 通过编号更新收货/发货地址服务
    /// </summary>
    public UpdateMdAddressByIdService updateMdAddressByIdService { get; set; }
    /// <summary>
    /// 通过编号更新收货/发货地址
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateMdAddressById([FromBody] RequestUpdateMdAddressByIdModel model)
    {
        return await Task.Run(() => updateMdAddressByIdService.Execute(model));
    }

    /// <summary>
    /// 通过编号获取收货/发货地址服务
    /// </summary>
    public GetMdAddressByIdService getMdAddressByIdService { get; set; }
    /// <summary>
    /// 通过编号获取收货/发货地址
    /// </summary>
    /// <param name="addressId">地址编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{addressId}")]
    public async Task<ResponseMessageModel> GetMdAddressById(long addressId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetMdAddressByIdModel();

        model.AddressId = addressId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getMdAddressByIdService.Execute(model));
    }

    /// <summary>
    /// 获取收货/发货地址列表服务
    /// </summary>
    public GetMdAddressListService getMdAddressListService { get; set; }
    /// <summary>
    /// 获取收货/发货地址列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetMdAddressList([FromBody] RequestGetMdAddressListModel model)
    {
        return await Task.Run(() => getMdAddressListService.Execute(model));
    }

    /// <summary>
    /// 分页获取收货/发货地址列表服务
    /// </summary>
    public GetMdAddressPageListService getMdAddressPageListService { get; set; }
    /// <summary>
    /// 分页获取收货/发货地址列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetMdAddressPageList([FromBody] RequestGetMdAddressPageListModel model)
    {
        return await Task.Run(() => getMdAddressPageListService.Execute(model));
    }
}

